home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / posix / sys / wait.h < prev   
C/C++ Source or Header  |  1994-01-24  |  5KB  |  144 lines

  1. /* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. /*
  20.  *    POSIX Standard: 3.2.1 Wait for Process Termination    <sys/wait.h>
  21.  */
  22.  
  23. #ifndef    _SYS_WAIT_H
  24.  
  25. #define    _SYS_WAIT_H    1
  26. #include <features.h>
  27.  
  28. __BEGIN_DECLS
  29.  
  30. #include <gnu/types.h>
  31.  
  32. /* This will define the `W*' macros for the flag
  33.    bits to `waitpid', `wait3', and `wait4'.  */
  34. #include <waitflags.h>
  35.  
  36. #ifdef    __USE_BSD
  37.  
  38. /* Lots of hair to allow traditional BSD use of `union wait'
  39.    as well as POSIX.1 use of `int' for the status word.  */
  40.  
  41. #ifdef    __GNUC__
  42. #define    __WAIT_INT(status)                              \
  43.   (__extension__ ({ union { __typeof(status) __in; int __i; } __u;          \
  44.             __u.__in = (status); __u.__i; }))
  45. #else
  46. #define    __WAIT_INT(status)    (*(int *) &(status))
  47. #endif
  48.  
  49. /* This is the type of the argument to `wait'.  With GCC 2.4 and later, the
  50.    funky union causes redeclarations with either `int *' or `union wait *'
  51.    to be allowed without complaint.  (__GNUC_MINOR__ is in fact only
  52.    defined in later versions, after 2.5.0; and versions prior to 2.6 have a
  53.    bug that produces bad code on some machines when using the union.)
  54.    __WAIT_STATUS_DEFN is the type used in the actual function definitions. */
  55.  
  56. #if    (!defined (__GNUC__) || __GNUC__ < 2 || \
  57.      (__GNUC__ == 2 && __GNUC_MINOR__ < 6))
  58. #define    __WAIT_STATUS        __ptr_t
  59. #define    __WAIT_STATUS_DEFN    __ptr_t
  60. #else
  61. #define    __WAIT_STATUS        union { union wait *__uptr; int *__iptr; }
  62. #define    __WAIT_STATUS_DEFN    int *
  63. #endif
  64.  
  65. #else /* Don't use BSD.  */
  66.  
  67. #define    __WAIT_INT(status)    (status)
  68. #define    __WAIT_STATUS        int *
  69. #define    __WAIT_STATUS_DEFN    int *
  70.  
  71. #endif /* Use BSD.  */
  72.  
  73. /* This will define all the `__W*' macros.  */
  74. #include <waitstatus.h>
  75.  
  76. #define    WEXITSTATUS(status)    __WEXITSTATUS(__WAIT_INT(status))
  77. #define    WTERMSIG(status)    __WTERMSIG(__WAIT_INT(status))
  78. #define    WSTOPSIG(status)    __WSTOPSIG(__WAIT_INT(status))
  79. #define    WIFEXITED(status)    __WIFEXITED(__WAIT_INT(status))
  80. #define    WIFSIGNALED(status)    __WIFSIGNALED(__WAIT_INT(status))
  81. #define    WIFSTOPPED(status)    __WIFSTOPPED(__WAIT_INT(status))
  82.  
  83. #ifdef    __USE_BSD
  84. #define    WCOREFLAG        __WCOREFLAG
  85. #define    WCOREDUMP(status)    __WCOREDUMP(__WAIT_INT(status))
  86. #define    W_EXITCODE(ret, sig)    __W_EXITCODE(ret, sig)
  87. #define    W_STOPCODE(sig)        __W_STOPCODE(sig)
  88. #endif
  89.  
  90.  
  91. /* Wait for a child to die.  When one does, put its status in *STAT_LOC
  92.    and return its process ID.  For errors, return (pid_t) -1.  */
  93. extern __pid_t __wait __P ((__WAIT_STATUS __stat_loc));
  94. extern __pid_t wait __P ((__WAIT_STATUS __stat_loc));
  95.  
  96. #ifdef    __USE_BSD
  97. /* Special values for the PID argument to `waitpid' and `wait4'.  */
  98. #define    WAIT_ANY    (-1)    /* Any process.  */
  99. #define    WAIT_MYPGRP    0    /* Any process in my process group.  */
  100. #endif
  101.  
  102. /* Wait for a child matching PID to die.
  103.    If PID is greater than 0, match any process whose process ID is PID.
  104.    If PID is (pid_t) -1, match any process.
  105.    If PID is (pid_t) 0, match any process with the
  106.    same process group as the current process.
  107.    If PID is less than -1, match any process whose
  108.    process group is the absolute value of PID.
  109.    If the WNOHANG bit is set in OPTIONS, and that child
  110.    is not already dead, return (pid_t) 0.  If successful,
  111.    return PID and store the dead child's status in STAT_LOC.
  112.    Return (pid_t) -1 for errors.  If the WUNTRACED bit is
  113.    set in OPTIONS, return status for stopped children; otherwise don't.  */
  114. extern __pid_t __waitpid __P ((__pid_t __pid, int *__stat_loc,
  115.                    int __options));
  116. extern __pid_t waitpid __P ((__pid_t __pid, int *__stat_loc,
  117.                  int __options));
  118. #ifdef    __USE_BSD
  119. /* This being here makes the prototypes valid whether or not
  120.    we have already included <sys/resource.h> to define `struct rusage'.  */
  121. struct rusage;
  122.  
  123. /* Wait for a child to exit.  When one does, put its status in *STAT_LOC and
  124.    return its process ID.  For errors return (pid_t) -1.  If USAGE is not
  125.    nil, store information about the child's resource usage there.  If the
  126.    WUNTRACED bit is set in OPTIONS, return status for stopped children;
  127.    otherwise don't.  */
  128. extern __pid_t __wait3 __P ((__WAIT_STATUS __stat_loc,
  129.                  int __options, struct rusage * __usage));
  130. extern __pid_t wait3 __P ((__WAIT_STATUS __stat_loc,
  131.                int __options, struct rusage * __usage));
  132.  
  133. /* PID is like waitpid.  Other args are like wait3.  */
  134. extern __pid_t __wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc,
  135.                  int __options, struct rusage *__usage));
  136. extern __pid_t wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc,
  137.                int __options, struct rusage *__usage));
  138. #endif /* Use BSD.  */
  139.  
  140.  
  141. __END_DECLS
  142.  
  143. #endif /* sys/wait.h  */
  144.